package com.example.examsystem.repository;

import com.example.examsystem.model.Permission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface PermissionRepository extends JpaRepository<Permission, Long> {
    
    Optional<Permission> findByResourceAndAction(String resource, String action);
    
    List<Permission> findByResource(String resource);
    
    List<Permission> findByAction(String action);
    
    boolean existsByResourceAndAction(String resource, String action);
    
    // 根据类型和可见性查询权限
    List<Permission> findByTypeAndVisible(Permission.PermissionType type, Boolean visible);
    
    // 根据类型查询权限
    List<Permission> findByType(Permission.PermissionType type);
    
    // 根据父级ID查询权限
    List<Permission> findByParentId(Long parentId);
    
    // 根据名称查询权限
    Optional<Permission> findByName(String name);
    
    // 按排序字段排序查询所有权限
    List<Permission> findAllByOrderBySort();
    
    // 检查名称是否存在
    boolean existsByName(String name);
    
    // 检查名称是否存在且ID不匹配
    boolean existsByNameAndIdNot(String name, Long id);
}








